package com.spring.mybatis.xml.service.impl;


import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;

import com.spring.mybatis.xml.dao.UserDao;
import com.spring.mybatis.xml.po.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.spring.mybatis.xml.service.UserService;

@Service("userService")
@Transactional(rollbackFor = Throwable.class)
public class SimpleUserService implements UserService {


  @Resource
  private UserDao userDao;

  @Override
  @Transactional(readOnly = true)
  public User selectById(String id) {
    return userDao.selectById(id);
  }

  @Override
  @Transactional(readOnly = true)
  public User selectByUserName(String username) {
    return userDao.selectByUserName(username);
  }

  @Override
  @Transactional(readOnly = true)
  public List<User> selectAll() {
    return userDao.selectAll();
  }

  @Override
  public String insert(User user) {
    user.setId(UUID.randomUUID().toString());
    userDao.insert(user);
    return user.getId();
  }

  @Override
  public boolean update(User user) {
    return userDao.update(user) == 1;
  }

  @Override
  public boolean delete(String id) {
    return userDao.deleteById(id) == 1;
  }
}
